home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / emcs1857 / 1857sr~1.zoo / lisp / emphasis.el < prev    next >
Encoding:
Text File  |  1992-01-24  |  5.5 KB  |  205 lines

  1. ;; Display characters with emphasis.
  2. ;; Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is distributed in the hope that it will be useful,
  7. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  8. ;; accepts responsibility to anyone for the consequences of using it
  9. ;; or for whether it serves any particular purpose or works at all,
  10. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  11. ;; License for full details.
  12.  
  13. ;; Everyone is granted permission to copy, modify and redistribute
  14. ;; GNU Emacs, but only under the conditions described in the
  15. ;; GNU Emacs General Public License.   A copy of this license is
  16. ;; supposed to have been given to you along with GNU Emacs so you
  17. ;; can know your rights and responsibilities.  It should be in a
  18. ;; file named COPYING.  Among other things, the copyright notice
  19. ;; and this notice must be preserved on all copies.
  20.  
  21.  
  22. ;; Written by Howard Gayle.  See case-table.el for details.
  23.  
  24. ;; This file uses the char table stuff to display characters
  25. ;; with emphasis, e.g. underlined.  The high order bit is set for
  26. ;; emphasis.  This implies a 7-bit character set, so this file
  27. ;; will not mix with ISO 8859.
  28.  
  29. (defvar emphasis-char-table nil "Char table where high bit set for emphasis.")
  30.  
  31. (defvar deemphasize-trans-table nil "Trans table to set high bit.")
  32. (if deemphasize-trans-table nil
  33.    (setq deemphasize-trans-table (make-trans-table))
  34.    (let     (
  35.            (i 128)
  36.      )
  37.       (while (<= i 255)
  38.            (set-trans-table-to i (- i 128) deemphasize-trans-table)
  39.            (setq i (1+ i))
  40.       )
  41.    )
  42. )
  43.  
  44. (defvar emphasize-trans-table nil "Trans table to set high bit.")
  45. (if emphasize-trans-table nil
  46.    (setq emphasize-trans-table (make-trans-table))
  47.    (let     (
  48.            (i 32)
  49.      )
  50.       (while (<= i 127)
  51.            (set-trans-table-to i (+ i 128) emphasize-trans-table)
  52.            (setq i (1+ i))
  53.       )
  54.    )
  55. )
  56.  
  57. (defvar start-emphasis nil "Bytes to terminal to start emphasis.")
  58. (defvar stop-emphasis  nil "Bytes to terminal to stop emphasis.")
  59.  
  60. (defun emphasis-on ()
  61.    "Use emphasis char table in selected window, if possible."
  62.    (interactive)
  63.    (init-emphasis-char-table-maybe)
  64.    (if emphasis-char-table (set-window-char-table emphasis-char-table))
  65. )
  66.  
  67. (defun deemphasize-region (b e)
  68.    "Emphasize the characters in region."
  69.    (interactive "*r")
  70.    (translate-region b e deemphasize-trans-table)
  71. )
  72.  
  73.  
  74. (defun emphasize-manual-entry ()
  75.    "Convert backspace underlining and overstriking to emphasis
  76. in the current buffer."
  77.    (interactive)
  78.    (let  (
  79.            (buffer-read-only nil)
  80.      )
  81.       (init-emphasis-char-table-maybe)
  82.       (if (and emphasis-char-table
  83.                  (underline-to-emphasis-region (point-min) (point-max)))
  84.            (setq buffer-char-table emphasis-char-table)
  85.       )
  86.    )
  87. )
  88.  
  89. (setq manual-entry-hook 'emphasize-manual-entry)
  90.  
  91. (defun emphasize-region (b e)
  92.    "Emphasize the characters in region."
  93.    (interactive "*r")
  94.    (translate-region b e emphasize-trans-table)
  95. )
  96.  
  97. (defun init-emphasis-char-table ()
  98.    "Initialize emphasis char table."
  99.    (interactive)
  100.    (setq emphasis-char-table (copy-char-table))
  101.    (let  (
  102.      (i 0) ; Current character.
  103.      j     ; Rope index.
  104.      r     ; Rope.
  105.      )
  106.       (while (<= i 127)
  107.      (setq r (get-char-table-dispr emphasis-char-table i))
  108.      (setq j 0)
  109.      (while (< j (length r))
  110.         (aset r j (get-glyf (concat start-emphasis
  111.                     (glyf-to-string (aref r j))
  112.                     stop-emphasis)))
  113.         (setq j (1+ j))
  114.      )
  115.      (put-char-table-dispr emphasis-char-table (+ i 128) r)
  116.      (setq i (1+ i))
  117.       )
  118.    )
  119. )
  120.  
  121. (defun init-emphasis-char-table-maybe ()
  122.    "Initialize emphasis char table if necessary."
  123.    (cond
  124.       (emphasis-char-table)
  125.       ((or (not (stringp start-emphasis))
  126.      (not (stringp stop-emphasis)))
  127.      (message "start-emphasis and stop-emphasis must be set."))
  128.       (t
  129.      (message "Making emphasis char table...")
  130.      (init-emphasis-char-table)
  131.      (message "Making emphasis char table...done")
  132.       )
  133.    )
  134. )
  135.  
  136. (defun underline-to-emphasis-buffer ()
  137.    "Convert backspace underlining and overstriking to emphasis
  138. in the current buffer."
  139.    (interactive)
  140.    (let  (
  141.            (buffer-read-only nil)
  142.      )
  143.       (if (underline-to-emphasis-region (point-min) (point-max))
  144.            (emphasis-on)
  145.       )
  146.    )
  147. )
  148.  
  149. (defun underline-to-emphasis-region (b e)
  150.    "Convert backspace underlining and overstriking to emphasis
  151. in the region.  Returns t iff any changes made."
  152.    (interactive "*r")
  153.    (let     (
  154.            (em (make-marker)) ; End marker.
  155.      fc                     ; Character following backspace.
  156.      pc                     ; Character preceding backspace.
  157.      tmp                    ; Temporary.
  158.      z                      ; Return.
  159.            )
  160.       (if (< e b)
  161.            (progn
  162.         (setq tmp b)
  163.         (setq b e)
  164.         (setq e tmp)
  165.      )
  166.       )
  167.       (move-marker em e)
  168.       (save-excursion
  169.            (goto-char b)
  170.            (while (search-forward "\b" em t)
  171.               (setq pc (char-after (- (point) 2)))
  172.         (setq fc (following-char))
  173.         (cond
  174.            ((= pc ?_)
  175.           (forward-char 1)
  176.           (delete-char -3)
  177.           (insert (get-trans-table-to fc emphasize-trans-table))
  178.           (setq z t)
  179.            )
  180.            ((= fc ?_)
  181.           (forward-char 1)
  182.           (delete-char -3)
  183.           (insert (get-trans-table-to pc emphasize-trans-table))
  184.           (setq z t)
  185.            )
  186.            ((= pc fc)
  187.                  (setq tmp (- (point) 2))
  188.           (forward-char 1)
  189.           (while (and (= (following-char) ?\b)
  190.                   (= (char-after (1+ (point))) pc))
  191.              (forward-char 2)
  192.           )
  193.           (delete-region tmp (point))
  194.           (insert (get-trans-table-to pc emphasize-trans-table))
  195.           (setq z t)
  196.            )
  197.         )
  198.      )
  199.       )
  200.       z
  201.    )
  202. )
  203.  
  204. (provide 'emphasis)
  205.